package cn.tedu.file;
/**
 * @Author 金帮嘉诚  @Date 2021-06-17 周四 19:55
 */
/*本类用于测试*/

import java.io.*;

/**
 知识点：
 OutputStream()
 FileOutputStream() 构造函数的第二个参数true是追加数据
 BufferedOutputStream()
 */
public class TestOut {
    public static void main(String[] args) {
        method1();
        method2();
    }

    private static void method2() {
        OutputStream out=null;

        try {
//            out=new BufferedOutputStream(new FileOutputStream(new File("D:\\ready\\9.txt"),true));
            out=new BufferedOutputStream(new FileOutputStream("D:\\ready\\9.txt",true));

            out.write(97);
            out.write(98);
            out.write(99);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method1() {
        OutputStream out=null;

        try {
//            out=new FileOutputStream(new File("D:\\ready\\9.txt"),true);
            out=new FileOutputStream("D:\\ready\\9.txt",true);

            out.write(99);
            out.write(98);
            out.write(97);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
